#include <ctype.h>
#include "bc.h"

int getch();
void ungetch(int);

int getop(char s[])
{
    int i, c;

    // jump over blanks
    while ((s[0] = c = getch()) == ' ' || c == '\t')
        ;
    s[1] = '\0';
    // if c is not number
    if (!isdigit(c) && c != '.')
        return c;

    // collect intger portion 
    i = 0;
    if (isdigit(c))
        while (isdigit(s[++i] = c = getch()))
            ;
    // collect  decimals portion
    if (c == '.')
        while (isdigit(s[++i] = c = getch()))
            ;
    s[i] = '\0';
    if (c != EOF)
        ungetch(c);

    return NUMBER;
}
